package com.itheima.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import org.hibernate.validator.constraints.Length;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.NotNull;
import java.util.Date;

public class User {
    private Integer id; //编号，唯一

    @NotNull(message = "用户名不能为空")
    @Length(min = 3,max=8,message = "用户名只能是3到8位")
    private String username; //用户名

    @NotNull(message ="密码不能为空" )
    @Length(min = 6,max = 18,message = "密码只能是6到18位")
    private String password; //密码
    @NotNull(message = "真实姓名不能为空")
    private String realname; //真实姓名
    @NotNull(message = "性别不嫩为空")
    @Length(min = 1,max = 1,message = "性别只能是男或者女")
    private String gender; //性别

    @DateTimeFormat(pattern = "yyyy-MM-dd")//给请求用的
    @JsonFormat(pattern = "yyyy-MM-dd",timezone = "Asia/Shanghai")//给响应用的
    @NotNull(message = "生日不能为空")
    private Date birthday; //生日

    public User() {
    }

    public User(Integer id,
                String username,
                String password,
                String realname,
                String gender,
                Date birthday) {
        this.id = id;
        this.username = username;
        this.password = password;
        this.realname = realname;
        this.gender = gender;
        this.birthday = birthday;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRealname() {
        return realname;
    }

    public void setRealname(String realname) {
        this.realname = realname;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("User{");
        sb.append("id=").append(id);
        sb.append(", username='").append(username).append('\'');
        sb.append(", password='").append(password).append('\'');
        sb.append(", realname='").append(realname).append('\'');
        sb.append(", gender='").append(gender).append('\'');
        sb.append(", birthday='").append(birthday).append('\'');
        sb.append('}');
        return sb.toString();
    }
}
